package org.black.missedCall2;

import java.util.List;

import org.black.missedCall2.object.CallInformation;

import android.os.Bundle;
import android.os.Handler.Callback;
import android.os.Message;
import android.widget.ListAdapter;
import android.widget.ListView;

public class MissedCallListCallback implements Callback {
	private MissedCallActivity missedCall;

	public MissedCallListCallback(final MissedCallActivity missedCall) {
		this.missedCall = missedCall;
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean handleMessage(Message msg) {

		Bundle bundle = msg.getData();
		Object object = bundle.get(MissedCallConstant.CALLS);
		ListView listView = (ListView) missedCall
				.findViewById(R.id.missedCalllistView);
		if (object == null) {
			ListAdapter listAdapter = listView.getAdapter();
			if (listAdapter != null) {
				MissedCallAdapter missedCallAdapter = (MissedCallAdapter) listAdapter;
				missedCallAdapter.reset();
				missedCallAdapter.notifyDataSetChanged();
			}

		} else {
			List<CallInformation> callInformations = (List<CallInformation>) object;
			ListAdapter listAdapter = listView.getAdapter();
			if (listAdapter != null) {
				MissedCallAdapter missedCallAdapter = (MissedCallAdapter) listAdapter;
				missedCallAdapter.reset(callInformations);
				missedCallAdapter.notifyDataSetChanged();
			}

		}
		return true;
	}

}
